<?php
class TranSaction_log extends Controller {
	function TranSaction_log() {
		parent::Controller();
		$this->load->helper("url");
		$this->data["base"] = $this->config->item('base_url');
		$this->load->model('TransLog');
		$this->load->database();	
                session_start();
	}
	function index() {
		if(isset($_SESSION['sys_admin']) and isset($_SESSION['name'])) {
			$this->formTransaction();
		} else if(isset($_SESSION['admin']) and isset($_SESSION['name'])){
			$this->formTransaction();
		} else if(isset($_SESSION['intern_audit']) and isset($_SESSION['name'])){
			$this->formTransaction();
		} else if(isset($_SESSION['second_consult']) and isset($_SESSION['name'])){
			$this->formTransaction();
		} else if(isset($_SESSION['dept_pic']) and isset($_SESSION['name'])){
			$this->formTransaction();
		} else {
			
			$this->load->view('layout/head', $this->data);
			$this->load->view('layout/body', $this->data);
			$this->load->view('layout/login-index', $this->data);
			$this->load->view('layout/footer', $this->data);
		}
	}
	var $limit = 20;
	function formTransaction($offset = 0) {
		$this->data['title']='Transaction Log';
		$this->data['h2_title'] = '';
		
		//certain offset
		$uri_segment = 4;
		$offset = $this->uri->segment($uri_segment);
		
		
		$id = $_SESSION['name'];
		$a = $this->TransLog->show_user_log($id)->row();
		$user_id = $a->name;
		$this->data['log'] = $this->TransLog->show_all_translog($user_id,$offset);
		$translog = $this->TransLog->show_all_translog($user_id,$offset)->result();
		$num_rows = $this->TransLog->count_all($user_id);
		
		
		if($num_rows > 0) {
			$config['base_url'] = site_url('translog/tranSaction_log/formTransaction');
			$config['total_rows'] = $num_rows;
			$config['per_page'] = $this->limit;
			$config['uri_segment'] = $uri_segment;
			$this->pagination->initialize($config);
			$this->data['pagination'] = $this->pagination->create_links();
			
			//set template table untuk efek selang-sling tiap bariS
				$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="450">','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','Name','Notes','Date Time','IP');
			$this->data['i'] = 0 + $offset;
			$i =0 + $offset;
			foreach($translog as $log) {
				$this->table->add_row(++$i,$log->name,$log->notes,$log->datetime,$log->ip);
			}
		}
		$this->data['table'] = $this->table->generate();
		
		$this->load->vars($this->data);
		$this->load->view('layout/head');
		$this->load->view('layout/body');
		$this->load->view('layout/slice-atas');
		$this->load->view('translog/translog');
		$this->load->view('layout/slice_bawah');
	}
}
?>